package com.linkhub.oms.data.sync.util;

import cn.hutool.crypto.SecureUtil;
import com.linkhub.oms.common.util.json.QtFastjsonUtil;
import com.linkhub.oms.data.sync.api.wms.domain.request.WmsBaseURLRequest;

/**
 * @Description: SignUtil
 * @Author: echo
 * @Date: 2024/5/5 20:28
 * @Version: 1.0
 */
public class SignUtil {

    public static String createWmsSign(WmsBaseURLRequest wmsBaseURLRequest, String secretKey, String body) {
        String sign = String.format("%s%s%s%s", secretKey, wmsBaseURLRequest.sortAndJoinFields(), body, secretKey);
        return SecureUtil.md5(sign).toUpperCase();
    }

    public static <T> String createWmsSign(T body, WmsBaseURLRequest wmsBaseURLRequest, String secretKey) {
        return createWmsSign(wmsBaseURLRequest, secretKey, QtFastjsonUtil.toJSONString(body));
    }
}
